package sorting

import "gitee.com/guuzaa/sorting/constraints"

func SelectionSort[T constraints.Ordered](arr []T) []T {
	for cur := len(arr) - 1; cur > 0; cur-- {
		maxIdx := 0
		for i := 1; i <= cur; i++ {
			if arr[i] > arr[maxIdx] {
				maxIdx = i
			}
		}

		arr[cur], arr[maxIdx] = arr[maxIdx], arr[cur]
	}

	return arr
}
